<template>
  <custom-container class="finance-report">
    <custom-container-header no-spacing>
      <el-form :model="filters" ref="form" :disabled="loading" inline size="medium" @submit.native.prevent="getAll"
        class="width-100">
        <el-form-item label="查询时间:">
          <el-date-picker v-model="filters.date" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期"
            :picker-options="{disabledDate: beforeToday.disabledDate}" value-format="timestamp"
            :default-time="['00:00:00', '23:59:59']">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="操作类型:">
          <el-select v-model="filters.optType">
            <el-option v-for="item in consts.REPORT_OPT_TYPES" :label="item.title" :key="item.value" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="账户名:">
          <el-input v-model="filters.username" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" native-type="submit">查询</el-button>
        </el-form-item>

        <el-form-item class="float-right" v-show="false">
          <custom-button-group v-model="time">
            <custom-button v-for="period in periods" :key="period.value" :label="period.value">
              {{period.title}}
            </custom-button>
          </custom-button-group>
        </el-form-item>
      </el-form>
    </custom-container-header>
    <custom-container-body>
      <el-table :data="tableData.data.list" :loading="loading" element-loading-text="加载中..." border border-radius
         :local-summary-method="getLocalSummaries"
         :summary-method="getSummaries"
         show-local-summary
         show-summary
         @sort-change="sortChange">
        <el-table-column align="center"  label="操作时间">
            <template slot-scope="{row}">
                {{ row.createTime | toTime}}
            </template>
        </el-table-column>

        <el-table-column align="center" prop="orderId" label="交易编号">
        </el-table-column>

        <el-table-column align="center" label="账户名">
          <template slot-scope="{row}">
            <!-- @click="openDetail(row)"  -->
            <!-- <el-button type="link" size="small" v-if="row.userType == 0">
              {{ row.userName}}
            </el-button> -->
              {{  row.modifyUserName ?  row.modifyUserName  : row.proxyUserName }}
          </template>
        </el-table-column>

        <el-table-column align="center" prop="userType" label="账户类型">
            <template slot-scope="{row}">
              <!-- {{ row.userType  == 0 ? '会员' : '代理' }} -->
              {{ row.modifyUserType ? (  row.userType  == 0 ? '会员' : '代理' ) :  ( row.optType == 4 ? '会员' : '代理' ) }}
            </template>
        </el-table-column>

        <el-table-column align="center" label="操作类型">
          <template slot-scope="{row}">
            {{row.optType | format_optType}}
          </template>
        </el-table-column>

        <el-table-column align="center" prop="changeAmount" label="变更金额">
          <template slot-scope="{row}">
            {{row.changeAmount | currency}}
          </template>
        </el-table-column>

        <el-table-column align="center" prop="creditedAmountBefore" label="额度变更前">
          <template slot-scope="{row}">
            <span v-if="userId != row.modifyUserId">{{row.creditedAmountBefore  | currency}}</span>
            <span v-else>{{row.modifyAmountBefore | currency}}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="creditedAmountAfter" label="额度变更后">
          <template slot-scope="{row}">
            <span v-if="userId != row.modifyUserId">{{row.creditedAmountAfter  | currency}}</span>
            <span v-else>{{row.modifyAmountAfter | currency}}</span>
          </template>
        </el-table-column>
        
        <template slot="empty">
          <div class="el-table__empty">
            <svg-icon class="el-table__empty-icon" icon-class="grid-empty-2"></svg-icon>
            <div class="el-table-text">暂无数据</div>
          </div>
        </template>
      </el-table>

      <div class="el-pagination-container">
        <el-pagination bordered @size-change="gridSizeChange" @current-change="gridCurrentChange"
          :current-page="filters.page" :page-size="filters.size" :total="Number(tableData.data.total)">
        </el-pagination>
      </div>
    </custom-container-body>
  </custom-container>
</template>

<script>
  import {upAmountApi as getApi, } from '@/services/api/report';
  import { grid, pickerOption } from '@/build';

  export default {
    name: "game-win-lose",

    mixins: [grid, pickerOption],
    filters: {
      format_optType: (type) => {
        type = typeof (type) == 'number' ? type : Number(type);
        switch (type) {
          // 1,2代理上分金额,3已配上分金额,4上分抵扣金额,5上分清算-账户余额
          case 1:
            return '上分清算-人工操作清算';
          case 2:
            return '代理上分';
          case 3:
            return '公司上分';
          case 4:
            return '会员上分';
          case 5:
            return '上分清算-账户余额清算';
          default:
            return '全部';
        }
      }
    },
    data() {
      // _.toTime
      return {
        filters: {
          date: undefined,
          page: 1,
          size: 10,
          optType: consts.ALL,
          username : undefined
        },
        time: consts.THIS_WEEK,
        periods: _.filter(consts.TIME_PERIOD, (period) => {
          return _.indexOf([consts.THIS_WEEK, consts.LAST_WEEK, consts.THIS_MONTH, consts.LAST_MONTH], period
            .value) !== -1;
        }),
        tableData: {
          data: [],
          sum: 0,
        },
        statistic: [
          {
            index: 1,
            prop: 'orderId',
            format: () => {
              return '';
            }
          },
          {
            index: 5,
            prop: 'tableData.sum.changeAmount',
            format: (value) => {
              return (<div> {_.currency(value)} </div>);
            }
          },
          {
            index: 6,
            prop: 'tableData.sum.creditedAmountBefore',
            format: (value) => {
              return '';
            }
          },
          {
            index: 7,
            prop: 'tableData.sum.creditedAmountAfter',
            format: (value) => {
              return '';
            }
          },
        ]
      };
    },
    computed:{
      ...mapGetters([
        'userId',
      ])
    },
    methods: {
      openDetail(row) {
        this.$memberDetail({
          info: {
            username: row.username,
            id: row.user_id,
            filters: this.filters,
          },
          callback: action => {
            if (action === 'success') {
              this.doGet({
                action: 'getGrid'
              });
            }
          }
        });
      },
    },

    mounted() {
      this.bindGet(getApi, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters',
        afterSuccess: (data)=>{
        
        }
      });
    }
  };
</script>